package com.codeoss.framework.report.query;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.codeoss.module.ir.service.IIrReportQueryService;

@Service
public class QueryDefStore implements IQueryDefStore {
	private Map<String, QueryDef> queryDefCache = new HashMap<String, QueryDef>();
	
	@Autowired
	private IIrReportQueryService irReportQueryService;
	
	@Override
	public QueryDef get(String code) {
		// TODO Auto-generated method stub
		QueryDef queryDef = queryDefCache.get(code);
		if (queryDef == null) {
			queryDef = QueryDefBuilder.build(code,irReportQueryService);
			queryDefCache.put(code, queryDef);
		}
		return queryDef;
	}

	@Override
	public void put(String code, QueryDef queryDef) {
		// TODO Auto-generated method stub
		queryDefCache.put(code, queryDef);
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		queryDefCache.clear();
	}

	@Override
	public QueryDef remove(String code) {
		// TODO Auto-generated method stub
		return queryDefCache.remove(code);
	}

}
